package domain;

import java_persistence.SystemAdministratorMapper;

/**
 * @author joseph simoneau <simoneau@gatech.edu>
 *
 */
public class SystemAdministrator extends User{

	public SystemAdministrator() {
		super();
	}
	
	public SystemAdministrator(  String un, String pw, String n, String pn, String ad, String em, Boolean aa ) {
		super ( un, pw, n, pn, ad, em, aa);
	}

	
	// Database functionality
	
	// CREATES
	
	/**Promotes 'this' to be a sysadmin within the database. 
	 * @param samap retrieved from a valid, open SqlSession object.
	 */
	public void create_sysadmin(SystemAdministratorMapper samap) {
		if( this.getUsername() != null ){
			samap.create_sysadmin( this.getUsername() );
		}
	}
	
	// RETRIEVES
	
	/**Retrieves a system administrator by username.  'this' will contain the SA's information or null if User 'username' does not exist or is not a sysadmin.
	 * @param username the username of the user
	 * @param samap retrieved froma  valid, open SqlSession obect.
	 */
	public void get_sa_by_username(String username, SystemAdministratorMapper samap) {
		SystemAdministrator temp = new SystemAdministrator();
		
		temp = samap.get_sa_by_username(username);
		
		this.setActive_account(temp.getActive_account());
		this.setAddress(temp.getAddress());
		this.setEmail(temp.getEmail());
		this.setName(temp.getName());
		this.setPassword(temp.getPassword());
		this.setPhone_number(temp.getPhone_number());
		this.setUsername(temp.getUsername());
		
	}
	
	// UPDATES
	
	// DELETES
	
	/**Demotes 'this' from being a sysadmin within the database.  
	 * @param samap retrieved from a valid, open SqlSession object.
	 */
	public void delete_sysadmin(SystemAdministratorMapper samap) {
		samap.delete_sysadmin( this.getUsername() );
	}
	
	
}
